package com.tian.config;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * {@code @description:} 微信支付配置
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024-10-10 11:17
 * {@code @version:} 1.0
 */
@Configuration
public class WXConfig {
    @Resource
    private WXPayConfig wxPayConfig;

    @Bean
    public Config config() {
        String resourceLocation = getClass().getClassLoader().getResource(wxPayConfig.getPrivateKeyPath()).getPath();
        return new RSAAutoCertificateConfig.Builder()
                        .merchantId(wxPayConfig.getMerchantId())
                        .privateKeyFromPath(resourceLocation)
                        .merchantSerialNumber(wxPayConfig.getMerchantSerialNumber())
                        .apiV3Key(wxPayConfig.getKey())
                        .build();
    }
}
